package com.steveproject.parttimeworktree.wxapi;


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import com.orhanobut.logger.Logger;
import com.steveproject.parttimeworktree.App;
import com.steveproject.parttimeworktree.utils.ToastUtil;
import com.tencent.mm.opensdk.constants.ConstantsAPI;
import com.tencent.mm.opensdk.modelbase.BaseReq;
import com.tencent.mm.opensdk.modelbase.BaseResp;
import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler;

/**
 * 微信支付
 */
public class WXPayEntryActivity extends Activity implements IWXAPIEventHandler {

    private static final String TAG = "WXPayEntryActivity";


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        App.getWXAPI().handleIntent(getIntent(), this);
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        setIntent(intent);
        App.getWXAPI().handleIntent(intent, this);
    }

    @Override
    public void onReq(BaseReq req) {
    }

    @Override
    public void onResp(BaseResp resp) {
        if (resp.getType() == ConstantsAPI.COMMAND_PAY_BY_WX) {
            Logger.i(TAG, "onPayFinish, errCode = " + resp.errCode);
            if (resp.errCode == 0) {//成功
                ToastUtil.showShort(this, "支付成功");
            } else if (resp.errCode == -1) {
                ToastUtil.showShort(this, "支付失败");
            } else if (resp.errCode == -2) {
                ToastUtil.showShort(this, "用户取消");
            }
        }
        finish();
    }
}